function UUtil() {
}

UUtil.CHARACTER_TYPE_Unknown = 'UK';
UUtil.CHARACTER_TYPE_Text = 'TE';
UUtil.CHARACTER_TYPE_IntegerNumeric = 'IN';
UUtil.CHARACTER_TYPE_RealNumeric = 'RN';
UUtil.CHARACTER_TYPE_OrderedMultiState = 'OM';
UUtil.CHARACTER_TYPE_UnorderedMultiState = 'UM';

UUtil.isProd = function() {
	return false;
};
UUtil.parseFloat = function(val) {
	try {
		return parseFloat(val);
	} catch (e) {
	}
	return 0;
};
UUtil.isNull = function(value) {
	if (!value || value.length < 1) {
		return true;
	}
	return false;
};
UUtil.nullToZero = function(val) {
	if (val) {
		return val;
	} else {
		return 0;
	}
};
UUtil.nullToNone = function(val, defaultVal) {
	if (val) {
		return val;
	}
	if (defaultVal) {
		return defaultVal;
	} else {
		return '';
	}
};

UUtil.isNumerical = function(val) {
	if (!val) {
		return true;
	}
	var len = val.length;
	var strValidChars = "0123456789.-";
	var ch;
	for ( var i = 0; i < len; i++) {
		ch = val.charAt(i);
		if (strValidChars.indexOf(ch) == -1) {
			return false;
		}
	}
	return true;
};

UUtil.isArray = function(val) {
	if (val instanceof Array) {
		return true;
	} else {
		return false;
	}
};

UUtil.isString = function(val) {
	if (typeof val == "string") {
		return true;
	} else {
		return false;
	}
};


UUtil.replace = function(str, searchFor, replaceTo) {
	if (!str) {
		return;
	}
	var len = str.length;
	var t = '';
	for ( var i = 0; i < len; i++) {
		var ch = str.charAt(i);
		if (ch == searchFor) {
			t += replaceTo;
		} else {
			t += ch;
		}
	}
	return t;
};

UUtil.undefinedTo = function(val, defaultValue) {
	if (val === undefined) {
		return defaultValue;
	} else {
		return val;
	}
}
UUtil.isUndefined = function(val) {
	return val === undefined;
};

UUtil.find = function(id) {
	return document.getElementById(id);
};

UUtil.log = function(str) {
	if (str) {
		window.status = str;
	}
};
UUtil.getScreenSize = function() {
	var dim = new Object();
	var winW = 630, winH = 460;

	if (parseInt(navigator.appVersion) > 3) {
		if (navigator.appName == "Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (document.all) {
			if (document.body) {
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
			}
		}
	}
	dim.width = winW;
	dim.height = winH;
	return dim;
};

UUtil.isMobile = function() {
	if (!navigator || !navigator.userAgent) {
		return null;
	}
	var list = [];
	list.push('iphone');
	list.push('ipod');
	list.push('ipad');
	list.push('android');
	list.push('blackberry');
	list.push('mini');
	list.push('palm');
	list.push('windows ce');

	var uagent = navigator.userAgent.toLowerCase();
	for ( var i = 0; i < list.length; i++) {
		var li = list[i];
		if (uagent.search(li) > -1) {
			return li;
		}
	}
	return null;
};

UUtil.moveToCenter = function(dom) {
	var win = UUtil.getScreenSize();
	var left = (win.width - dom.offsetWidth) / 2;
	if (document.body) {
		left += document.body.scrollLeft;
	}
	var top = (win.height - dom.offsetHeight) * 2 / 5;
	if (document.body) {
		top += document.body.scrollTop;
	}
	if (left < 0) {
		left = 0;
	}
	if (top < 0) {
		top = 0;
	}
	dom.style.left = left + 'px';
	dom.style.top = top + 'px';
};

UUtil.getParameters = function() {
	var vars = [], hash;
	var hashes = window.location.href.slice(
			window.location.href.indexOf('?') + 1).split('&');
	for ( var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
};
UUtil.escapeHTML = function(str) {
	if (!str) {
		return str;
	}
	return str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
UUtil.getImageURL = function(image) {
	if (!image || UUtil.isNull(image.f)) {
		return null;
	}
	return UKey.getInstance().getData().imagePath + '/' + image.f;
};

UUtil.getStringBeforeDot = function(str) {
	if (UUtil.isNull(str)) {
		return str;
	}

	var index = str.lastIndexOf('.');
	if (index > 0) {
		var name = str.substring(0, index);
		if (!UUtil.isNull(name)) {
			return name;
		}
	}
	return str;
}

UUtil.getTaxaImage = function(data, fileName, w, h) {
	var prefix = UUtil.getStringBeforeDot(fileName);
	if (UUtil.isNull(prefix)) {
		return fileName;
	}
	return UUtil.getImageDir(data) + prefix + '_' + w + '_' + h + '.png';
}
UUtil.getTaxaThumbNailImage = function(data, fileName) {
	return UUtil.getTaxaImage(data, fileName, 115, 115);
}
UUtil.getTaxaMobileImage = function(data, fileName) {
	return UUtil.getTaxaImage(data, fileName, 400, 400);
}
UUtil.getTaxaOriginalImage = function(data, fileName) {
	if (UUtil.isNull(fileName)) {
		return fileName;
	}
	return UUtil.getImageDir(data) + fileName;
}
UUtil.getImageDir = function(data) {
	return 'Data_Release' + '/' + data.dataDir + '/img/';
}

UUtil.indexOnLoad = function(str) {
	var url;
	if (UUtil.isSmallScreen()) {
		url = 'index_m.php';
	} else {
		url = 'index_d.php';
	}
	window.location.href = url;
}

UUtil.isSmallScreen = function() {
	var isMobile = UUtil.isMobile();
	if (!UUtil.isNull(isMobile)) {
		if (isMobile != 'ipad') {
			var dim = UUtil.getScreenSize();
			if (dim && dim.width > 500) {
				return false;
			} else {
				return true;
			}
		}
	}
	return false;
}

	
